package com.giao.controller;

import com.giao.pojo.ContractProductC;
import com.giao.service.ConProductService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/ConProduct")
public class ConProductController {
    @Resource
    private ConProductService conProductService;

    //查询全部
    @RequestMapping("/findAllConProduct")
    public String findAllConProduct(Model model) {
        List<ContractProductC> contractProductCS = conProductService.findAllConProduct();
        model.addAttribute("o", contractProductCS);
        return "basicinfo/factory/jContractProductCreate";
    }

    //跳转到添加页面
    @RequestMapping("/jContractProductCreate")
    public String ToInsertConProduct() {
        return "basicinfo/factory/jContractProductCreate";
    }

    //添加方法
    @RequestMapping("/insertConProduct")
    public String insertConProduct(ContractProductC contractProductC) {
        conProductService.insertConProduct(contractProductC);
        return "redirect:/ConProduct/findAllConProduct";
    }

    //删除
    @RequestMapping("/deleteConProduct/{contract_product_id}")
    public String deleteConProduct(@PathVariable("contract_product_id") int id) {
        conProductService.deleteConProduct(id);
        return "redirect:/ConProduct/findAllConProduct";
    }

    //去修改页面
    @RequestMapping("/jContractProductUpdate")
    public String ToUpdateConProduct(int id, Model model) {
        ContractProductC contractProductC = conProductService.findByConProductId(id);
        model.addAttribute("updateCp", contractProductC);
        return "basicinfo/factory/jContractProductUpdate";
    }

    //修改方法
    @RequestMapping("/updateConProduct")
    public String updateConProduct(ContractProductC contractProductC) {
        conProductService.updateConProduct(contractProductC);
        return "redirect:/ConProduct/findAllConProduct";
    }
}
